#!/usr/bin/env python
# -*- encoding: UTF-8 -*-
from __future__ import print_function

from .. import db
from .. import myprint
from .. import flag
from .. import main
from .. import api
from .. import forms
from .. import models
from .. import global_dict

camManger = models.Cam.CamManger() # 相机管理器,单例模式

Cam = models.Cam.Cam
Image = models.Image.Image
Motion = models.Motion.Motion
Nao = models.Nao.Nao

@main.before_request
def before_request():
    Image.remove_invalid_images()

#================= 实用函数 ===============

@main.route('/video/camera/<int:cam_id>')
def video_feed(cam_id):
    if camManger.has(cam_id):
        cam_video = camManger.get_video(cam_id)
        return cam_video.video_Response(scale=0.25,real=False)

@main.route('/real/video/camera/<int:cam_id>')
def real_video_feed(cam_id):
    if camManger.has(cam_id):
        cam_video = camManger.get_video(cam_id)
        return cam_video.video_Response(scale=0.125,real=True)
